找传奇、传世资源到传世资源站!

mvc多国语言网站解决方案 MvcResourceLang

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

代码:using System;using System.Collections.Generic;using System.Linq;using System.Reflection;using System.Threading;using System.Web;using System.Web.Mvc;namespace MvcResourceLang.Models {public static class LangHelper {//界面普通文字的多语言public static string GetLangbyKey(this HtmlHelper htmlhelper, string key) {Type resourceType = (Thread.CurrentThread.CurrentUICulture.Name == "en-US") ? typeof(Resources.en_US) : typeof(Resources.zh_CN);PropertyInfo p = resourceType.GetProperty(key);if (p != null)return p.GetValue(null, null).ToString();elsereturn "undefined";}//js定义多语言弹出框public static string LangOutJsVar(this HtmlHelper htmlhelper, string key) {Type resourceType = (Thread.CurrentThread.CurrentUICulture.Name == "en-US") ? typeof(Resources.en_US) : typeof(Resources.zh_CN);PropertyInfo p = resourceType.GetProperty(key);if (p != null)return string.Format("var {0} = '{1}'", key, p.GetValue(null, null).ToString());elsereturn string.Format("var {0} = '{1}'", key, "undefined");}}}

前台:<body> <div> @{ string controller = ViewContext.Controller.ValueProvider.GetValue("controller").RawValue.ToString(); string action = ViewContext.Controller.ValueProvider.GetValue("action").RawValue.ToString(); //string lang = ViewContext.Controller.ValueProvider.GetValue("lang").RawValue.ToString(); } @Html.ActionLink("中文", action, new { Controller = controller, lang = "zh-CN" }, new { @class = "btn-a" }) @Html.ActionLink("English", action, new { Controller = controller, lang = "en-US" }, new { @class = "btn-a" }) </div> <h2>@Html.GetLangbyKey("LogonDisplay")</h2> <div class="logon-div"> @using (Html.BeginForm()) { <table> <tr> <td>@Html.LabelFor(m => m.UserName)</td> <td>@Html.TextBoxFor(m => m.UserName, new { style = "width:100%" })</td> </tr> <tr> <td>@Html.LabelFor(m => m.Pwd)</td> <td>@Html.PasswordFor(m => m.Pwd, new { style = "width:100%" })</td> </tr> <tr> <td colspan="2">@Html.CheckBoxFor(m => m.Rememberme) @Html.LabelFor(m => m.Rememberme) <input type="submit" value="@Html.GetLangbyKey("LogonDisplay")" style="float:right;"/> </tr> <tr style="font-size: 12px;"> <td colspan="2"> @Html.GetLangbyKey("NoteDisplay") @Html.ActionLink(Html.GetLangbyKey("RegisterDisplay"), "Register", null, null) . </tr> </table> } </div></body>

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复